package com.zking.dao;

import com.zking.entity.Evaluate;
import java.sql.SQLException;
import java.util.List;

public class EvaluateDao extends BaseDaoImpl{
    /**
     * 查询所有的评价
     *evaluate
     * @return
     */
    public List<Evaluate> queryEvaluates(String shopname) {
        String sql = "select * from evaluate where shopname ='" + shopname + "'; ";
        try {
            return findList(Evaluate.class, sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 添加评价
     *
     * @param
     * @return
     */
    public int insertEvaluate(Evaluate evaluate) {
        String sql = "insert into evaluate values(?,?,?,?,?)";
        Object[] params = { evaluate.getShopname(),evaluate.getContent(),evaluate.getUsername(),evaluate.getStar(),evaluate.getTime()};
        try {
            return update(sql, params);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
    public int updateRely(String content,String time){
        String sql = "UPDATE evaluate SET content = ? WHERE time = ? ";
        try {
            return update(sql, content,time);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
   /* *//**
     * 修改评价
     *
     * @param evaluate
     * @return
     *//*
    public int updateEvaluate(Evaluate evaluate) {
        String sql = "UPDATE `evaluate` SET " + "`shopname` = ?, `content` = ? WHERE `address` = ?";
        Object[] params = { evaluate.getShopname(),evaluate.getContent()};
        try {
            return update(sql, params);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }*/

    /**
     * 删除评价
     *
     * @return
     */
      public int deleteEvaluate(String evaluate) {
          String sql = "delete evaluate address where content=?";
          Object[] params = {evaluate};
          try {
              return update(sql, params);
          }
          catch (SQLException e) {
              e.printStackTrace();
          }
          return 0;
      }


}
